home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-12-11 | 8.4 KB | 350 lines | [TEXT/MPS ] |
- /*
- File: Promise.cpp
-
- Contains: Promise Classes Implementation
-
- Written by: Dave Stafford
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- */
-
- // -- Compiler/Preprocessor Switches --
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- DrawEditor Includes --
-
- #ifndef _SHAPES_
- #include "Shapes.h"
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _ORDCOLL_
- #include "OrdColl.h"
- #endif
-
- #ifndef _SELECTION_
- #include "Selection.h"
- #endif
-
- #ifndef _PROMISE_
- #include "Promise.h"
- #endif
-
- #ifndef _DRAWEDITOR_
- #include "DrawEditor.h"
- #endif
-
- #ifndef _DRAWEDITORUTILS_
- #include "DrawEditorUtils.h"
- #endif
-
- #ifndef _DRAWEDITORCONSTANTS_
- #include "DrawEditorConstants.h"
- #endif
-
- #ifndef _DRAWEDITORGLOBALS_
- #include "DrawEditorGlobals.h"
- #endif
-
- #ifndef _SAMPLECOLLECTIONS_
- #include "SampleCollections.h"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h" // ODDisposePtr
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _FOCUSLIB_
- #include <FocusLib.h>
- #endif
-
- // -- Toolbox Includes --
-
- #ifndef mathRoutinesIncludes
- #include <math routines.h>
- #endif
-
- #ifndef __MEMORY__
- #include <memory.h>
- #endif
-
-
-
- // **************************** Need to improve Handling of Failure **********************
-
-
- //=============================================================================
- // CPromise
- //=============================================================================
-
- //----------------------------------------------------------------------------------------
- // CPromise::CPromise
- //----------------------------------------------------------------------------------------
-
- CPromise::CPromise(DrawEditor* editor,
- ODFrame* sourceFrame,
- CSelection* selection,
- ODCloneKind kind)
- {
- fDrawEditor = editor;
- fSourceFrame = sourceFrame;
- fCloneKind = kind;
-
- // copies the content lists
- fPromiseContent = new CPromiseContent(selection->GetSelectionContent());
- }
-
-
- //----------------------------------------------------------------------------------------
- // CPromise::~CPromise
- //----------------------------------------------------------------------------------------
-
- CPromise::~CPromise()
- {
- delete fPromiseContent;
- }
-
-
- //----------------------------------------------------------------------------------------
- // CPromise::Promise
- //----------------------------------------------------------------------------------------
-
- void CPromise::Promise(Environment *ev, ODStorageUnit* storageUnit)
- {
- CPromise* buffer = this;
- ODByteArray promiseByteArray;
- promiseByteArray._length = sizeof(CPromise*);
- promiseByteArray._maximum = sizeof(CPromise*);
- promiseByteArray._buffer = (octet*)&buffer;
-
- ODPart* part = fDrawEditor->GetODPart();
-
- // Must use a clone transaction, even to write a promise
- ODDraft* fromDraft = fDrawEditor->GetDraft(ev);
- ODDraftKey key = kODNULLID;
-
- TRY
- key = fromDraft->BeginClone(ev, storageUnit->GetDraft(ev),
- fSourceFrame, fCloneKind);
- storageUnit->SetPromiseValue(ev, fDrawEditor->GetEditorKind(), 0,
- &promiseByteArray, part);
- fromDraft->EndClone(ev, key);
- CATCH_ALL
- if (key!=kODNULLID)
- fromDraft->AbortClone(ev, key);
- ENDTRY
- }
-
-
-
-
- //----------------------------------------------------------------------------------------
- // CPromise::FulFillPromise
- //----------------------------------------------------------------------------------------
-
- void CPromise::FulfillPromise(Environment* ev, ODStorageUnit* storage)
- {
- COrderedList* shapes = kODNULL;
-
- ODDraft* fromDraft = fDrawEditor->GetDraft(ev);
-
- // Define clone information
- CCloneInfo info(0, fromDraft, fSourceFrame, fCloneKind);
-
- TRY
- ODDraft* dstDraft = storage->GetDraft(ev);
-
- fPromiseContent->Externalize(ev, storage, &info);
- CATCH_ALL
- RERAISE;
- ENDTRY
- }
-
- //----------------------------------------------------------------------------------------
- // CPromise::FulFillPromise
- //----------------------------------------------------------------------------------------
-
- void CPromise::FulfillPromise(Environment* ev, ODStorageUnitView* view)
- {
- this->FulfillPromise(ev, view->GetStorageUnit(ev));
- }
-
- //----------------------------------------------------------------------------------------
- // CPromise::GetShapeList
- //----------------------------------------------------------------------------------------
-
- COrderedList* CPromise::GetShapeList()
- {
- return fPromiseContent->GetShapeList();
- }
-
- //----------------------------------------------------------------------------------------
- // CPromise::GetPromiseContent
- //----------------------------------------------------------------------------------------
- CDrawContent* CPromise::GetPromiseContent()
- {
- return fPromiseContent;
- }
-
- #pragma segment Main
- CPromise::CPromise(DrawEditor* editor,
- ODFrame* sourceFrame,
- COrderedList* shapeList,
- ODCloneKind kind)
- {
- fDrawEditor = editor;
- fSourceFrame = sourceFrame;
- fCloneKind = kind;
-
- fPromiseContent = new CPromiseContent(editor, shapeList);
- }
-
-
-
-
-
- //=============================================================================
- // CClipboardPromise
- //=============================================================================
- //----------------------------------------------------------------------------------------
- // CClipboardPromise::CClipboardPromise
- //----------------------------------------------------------------------------------------
-
- CClipboardPromise::CClipboardPromise(DrawEditor* editor,
- ODFrame* sourceFrame,
- CSelection* selection,
- ODCloneKind kind,
- ODUpdateID updateID) : CPromise( editor, sourceFrame, selection, kind )
- {
- fUpdateID = updateID;
- }
-
-
- //----------------------------------------------------------------------------------------
- // CClipboardPromise::~CClipboardPromise
- //----------------------------------------------------------------------------------------
-
- CClipboardPromise::~CClipboardPromise()
- {
- }
-
-
- //----------------------------------------------------------------------------------------
- // CClipboardPromise::Promise
- //----------------------------------------------------------------------------------------
-
- void CClipboardPromise::Promise(Environment *ev, ODStorageUnit* storageUnit)
- {
- CPromise::Promise(ev, storageUnit);
-
- // Check the global promise, if its not null delete it
- if (gGlobals->fClipboardPromise)
- {
- // Mark shapes no longer promised to the clipboard
- gGlobals->fClipboardPromise->ShapesPromisedToClipboard(ev, kODFalse);
-
- delete gGlobals->fClipboardPromise;
- }
-
- // Remember this promise, in case it never gets fulfilled so we can
- // clean up the storage
- gGlobals->fClipboardPromise = this;
-
- // Mark shapes as promised to the clipboard
- this->ShapesPromisedToClipboard(ev, kODTrue);
- }
-
-
-
-
- //----------------------------------------------------------------------------------------
- // CClipboardPromise::ShapesPromisedToClipboard
- //----------------------------------------------------------------------------------------
-
- void CClipboardPromise::ShapesPromisedToClipboard(Environment *ev, ODBoolean promised)
- {
- COrdListIterator iter(fPromiseContent->GetShapeList());
- for (CShape* shape = (CShape*)iter.First();
- iter.IsNotComplete();
- shape = (CShape*)iter.Next())
- {
- shape->SetPromisedToClipboard(promised);
- }
- }
-
-
- //----------------------------------------------------------------------------------------
- // CClipboardPromise::FulFillPromise
- //----------------------------------------------------------------------------------------
-
- void CClipboardPromise::FulfillPromise(Environment* ev, ODStorageUnit* storage)
- {
- // Our parent method could throw, we need to make sure we get a chance to
- // execute even if it does throw.
- TRY
- // Call inherited
- CPromise::FulfillPromise(ev, storage);
-
- this->ShapesPromisedToClipboard(ev, kODFalse);
-
- CATCH_ALL
- ENDTRY
-
- // If this promise isn't the one in gGlobals->fClipboardPromise, something is awry
- if (gGlobals->fClipboardPromise!=this)
- {
- DebugStr("\pThis should not happen.");
- }
- else
- // When a promise to the clip is fulfilled, the global should be set to null
- // This must be done whether or not the base class method succeeds or fails.
- gGlobals->fClipboardPromise = kODNULL;
-
- }
-
-
- #pragma segment Main
- ODUpdateID CClipboardPromise::GetUpdateID()
- {
- return fUpdateID;
- }
-
-